package com.example.news.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.news.mapper.NewsMapper;
import com.example.news.pojo.News;
import com.example.news.pojo.NewsType;
import com.example.news.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {
            @Autowired
            private NewsMapper newsMapper;


    @Override
    public Page<News> searchPage(News news, Integer pageNum, Integer pageSize) {
        String newsName = news.getNewsName();
        //创建分页对象
        Page<News> page = new Page<>(pageNum, pageSize);
        //执行分页查询
        LambdaQueryWrapper<News> queryWrapper = new LambdaQueryWrapper<>();
        if (newsName != null && !newsName.isEmpty()) {
            queryWrapper.like(News::getNewsName, newsName);
        }
        //执行查询
        Page<News> resultPage = page(page, queryWrapper);

        //返回结果
        return resultPage;
    }


}

